<?php
class shixue extends admin{
   public function __construct(){
      parent::__construct();
      array_walk_recursive($_GET, 'safe_filter');
      array_walk_recursive($_POST, 'safe_filter');
   }

   public function index(){
      $school_id=(int)$_SESSION['client']['jx_id'];
      $where=' where school_id='.$school_id;
      if(isset($_GET['k'])&&$_GET['k']!='') {
         $k=trim($_GET['k']);
         if(preg_match('/^1[3-9][0-9]{9}$/',$k)) $where.=' and mobile like "%'.$k.'%"';
         else $where.=' and real_name like "%'.$k.'%"';
      }
      if(isset($_GET['status'])&&is_numeric($_GET['status'])) $where.=' and status='.(int)$_GET['status'];

      $total=db()->getOne('select count(*) from x_shixue '.$where);
      if(isset($_GET['pagesize'])&&(int)$_GET['pagesize']>0) $pagesize=(int)$_GET['pagesize'];
      else $pagesize=C('PAGE_SIZE');
      if(isset($_GET['p'])&&(int)$_GET['p']>0) $p=(int)$_GET['p'];
      else $p=1;
      $max_p = ceil($total/$pagesize);
      if($p>=$max_p) $p = $max_p;
      $limit=' limit '.($p-1)*$pagesize.','.$pagesize;
      $list=db()->getAll('select * from x_shixue '.$where. ' order by id DESC '.$limit);
      $page = array('total' => $total, 'pagesize' => $pagesize, 'curpage' => $p);
      $this->ajaxReturn(array('status'=>1,'data'=>$list,'page'=>$page));
   }

   public function update(){
      $id = (int) $_POST['id'];
      $data['status'] = (int) $_POST['status'];
      $data['remark'] = remove_xss($_POST['remark']);
      $affert_num = db()->update('x_shixue', $data, 'id=' . $id);
      if ($affert_num!==false) {
         if ($affert_num>0)  insertlogs('update','修改试学(ID:'.$id.')',$data,'id='.$id);
         $this->ajaxReturn(array( 'status' => '1', 'info' => '操作成功' ));
      }
      else $this->ajaxReturn(array( 'status' => '0', 'info' => '操作失败' ));

   }
}
